package com.bjpowernode.controller;

import com.bjpowernode.constant.DicEnum;
import com.bjpowernode.entity.TDicValue;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.DicTypeService;
import com.bjpowernode.service.DicValueService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据字典
 */
@RestController
@RequiredArgsConstructor
public class DicController {

    private final DicValueService dicValueService;

    /**
     * 获取数据字典
     *  方案1:从缓存中获取数据字典数据（定时任务已经查出）
     *  方案2：从数据库中查询数据字典数据
     * @param typeCode
     * @return
     */
    @GetMapping("/api/dic/{typeCode}")
    public Result getDic(@PathVariable String typeCode) {

        List<TDicValue> tDicValueList = dicValueService.getDicValueByTypeCode(typeCode);

        return Result.OK(tDicValueList);
    }
}
